package com.leoman.dao;

import com.leoman.entity.LetterAccept;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * LetterAcceptDao
 * Created by 涂奕恒 on 2016/11/23 0023 下午 3:43.
 */
public interface LetterAcceptDao extends JpaRepository<LetterAccept, Integer>, JpaSpecificationExecutor<LetterAccept> {

    @Query("select a from LetterAccept a where a.user.id = ?1 and a.letter.id = ?2 and a.moneyStatus = 1")
    List<LetterAccept> findListByParams(Integer userId, Integer letterId);

    @Query("select a from LetterAccept a where a.user.id = ?1 and a.letter.isDraft = 0 and a.letter.moneyStatus = 1")
    Page<LetterAccept> iPageByUserId(Integer userId, Pageable pageable);

    @Query("select a from LetterAccept a where a.letter.id = ?1")
    List<LetterAccept> findListByLetterId(Integer letterId);

    @Query("select a from LetterAccept a where a.letter.id = ?1")
    Page<LetterAccept> iPageByLetterId(Integer letterId, Pageable pageable);
}